/**
 * @author liuxin
 * @e-mail lxtobe5@gmail.com
 * @lasttime 2011 11.14
 * @langversion ActionScript 3.0
 * @playerversion Flash 9.0 - 11.0
 * @tiptext
 */
package SpeedCompare_sample
{
	import flash.display.Sprite;
	import flash.system.System;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;
	import flash.utils.getTimer;

	public class Common extends Sprite
	{
		public var test_int:int       = 1000000000;
		public var test_uint:uint     = 1000000000;
		public var test_Number:Number = 1000000000;
		public var times:uint         = 100000000;
		public var int_times:int      = 10000000;
		public var numbers:uint       = 1000000;
		public var oldtime:int;
		public var byteArray:ByteArray = new ByteArray();
		
		public function getExecuteTime():void
		{
			trace("execute time: " + (getTimer() - oldtime) + "ms");
		}
		
		public function setOldTime():void
		{
			oldtime = getTimer();
		}
		
		public function getSystemInfo():void
		{
			trace("System.freeMemory: "+System.freeMemory);
			trace("System.totalMemory: "+System.totalMemory);
			trace("System.totalMemoryNumber: "+System.totalMemoryNumber);
		}
		
		public function getArray():Array
		{
			var a:Array = [];
			for (var i:uint = 0; i < numbers; i++) 
			{
				a[i] = i;
			}
			return a;
		}
		
		public function getAssignObject(o:*):*
		{
			for (var i:uint = 0; i < numbers; i++) 
			{
				o["k"+i] = "i" + i;
			}
			trace("create time: " + (getTimer() - oldtime) + "ms");
			setOldTime();
			return o;
		}
		
		public function forin(o:*):void
		{
			for (var i:* in o)
			{
				
			}
			trace("for...in time: " + getCurrentTime() + "ms");
			setOldTime();
		}
		
		public function foreachin(o:*):void
		{
			for each (var i:* in o)
			{
				
			}
			trace("for...each...in time: " + getCurrentTime() + "ms");
			setOldTime();
		}
		
		private function getCurrentTime():int
		{
			return (getTimer() - oldtime);
		}
	}
}